﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data.Sql;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;

using DataAccessLayer;
using lib;
using lib.Twitter;
using lib.JsonParser;
using myTwitter;
using Yedda;

namespace ConsoleTest
{
    
    class Program
    {
        static void Main(string[] args)
        {
            myTwitter.myTwitter twitter = new myTwitter.myTwitter("joggz", "testtest");
           
            // Authenticate user
            if (!twitter.authUser())
            {
                Console.WriteLine("ERROR COULD NOT AUTHENTICATE USER!");
                Console.ReadKey();
                return;
            }
            
            // Request data from twitter
            //String json = twitter.getPublicTimeline();
            String json = twitter.getFriendStatus();

            // Parse json string to jsonObject
            Object jsonObject = JsonParser.parseJson(json);

            // Parse jsonObject to list of object for the databse tables
            List<Object> olist = JsonTwitter.jsonToTwitter(jsonObject, "Status");

            // Insert objects to database: Need myUser
            //lib.Twitter.TwitterLinq.insertTwitter(olist);

            // Get all the statuses in the db, newst first in the list
            // and the oldest last
            List<Status> statuses = lib.Twitter.TwitterLinq.getOrderedStatuses();

            foreach (Status s in statuses)
            {
                Console.WriteLine("{0}", s.text);
                Console.WriteLine("======================================================");
            }

            Console.ReadKey();
            return;
        }
    }
}
